<?php
// +----------------------------------------------------------------------
// | 会员管理
// +----------------------------------------------------------------------
// | Author: Helly
// +----------------------------------------------------------------------
// | Date: 2014/11/18 15:52
// +----------------------------------------------------------------------

namespace Admins\Controller;

use Common\Controller\AdminBase;

class UserController extends AdminBase {

    //会员列表显示
    public function index() {
        if (IS_POST) {
            $this->redirect('index', $_POST);
        }
        
        $menuid = I('menuid');
        if($menuid == 21){
            $where['uemail'] = array("NOTLIKE", "hb%@163.com");
        }else{
            $where['uemail'] = array("LIKE", "hb%@163.com");
        }

        //搜索
        $search = I('get.search');
        if (!empty($search)) {
            $this->assign("search", $search);
            //添加开始时间
            $start_time = I('get.start_time');
            if (!empty($start_time)) {
                $start_time = strtotime($start_time);
                $where['create_time'] = array("EGT", $start_time);
                $this->assign('start_time', $start_time);
            }
            //添加结束时间
            $end_time = I('get.end_time');
            if (!empty($end_time)) {
                $end_time = strtotime($end_time);
                $where['create_time'] = array("ELT", $end_time);
                $this->assign('end_time', $end_time);
            }
            //时间搜索条件
            if ($end_time > 0 && $start_time > 0) {
                $where['create_time'] = array(array('EGT', $start_time), array('ELT', $end_time));
            }
            //是否审核
            $status = I('get.status', 2, 'intval');
            if ($status!=2) {
                $where["status"] = array("EQ", $status);
            }
            $this->assign("status", $status);

            //是否认证
            $ifrz = I('get.ifrz', 4, 'intval');
            if ($ifrz<4) {
                $where["ifrz"] = array("EQ", $ifrz);
            }elseif($ifrz==3){
                $where['ifrequest']=array('EQ',true);
            }
            $this->assign("ifrz", $ifrz);
            //搜索字段
            $searchtype = I('get.searchtype', null, 'intval');
            //搜索关键字
            $keyword = \Input::getVar(I('get.keyword'));
            if (!empty($keyword)) {
                $this->assign("searchtype", $searchtype);
                $this->assign("keyword", $keyword);
                $type_array = array('nickname', 'umobile', 'uemail');
                if ($searchtype < 3) {
                    $searchtype = $type_array[$searchtype];
                    $where[$searchtype] = array("LIKE", "%{$keyword}%");
                }
            }
        }else{
            $this->assign("status", 2);
            $this->assign("ifrz", 4);
        }

        $model=M('user');
        $count = $model->where($where)->count();
        $page = $this->page($count, 20);
        $data = $model->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("userid" => "DESC"))->select();


        $this->assign('Page', $page->show());
        $this->assign('count', $count);
        $this->assign('data', $data);
        $this->display();
    }


    //修改用户信息
    public function edit(){
        if(IS_POST){

            if (false !== D('Admins/User')->editUser($_POST)) {
                $this->success("信息更新成功！", U("User/index"));
            } else {
                $error = D('Admins/User')->getError();
                $this->error($error ? $error : '信息修改失败！');
            }
        }else{
            $userid=I('get.userid',0,'intval');
            $where=array('userid'=>$userid);
            $this->user=M('user')->where($where)->find();
            $this->province=M('province')->select();
            $this->display();
        }
    }


    //添加用户
    public function add() {
        if (IS_POST) {
            if (D('Admins/User')->createUser($_POST)) {
                $this->success("添加会员成功！", U('User/index'));
            } else {
                $error = D('Admins/User')->getError();
                $this->error($error ? $error : '添加失败！');
            }
        } else {
            $this->display();
        }
    }


    //删除用户
    public function delete() {
        $id = I('get.userid', 0, 'intval');
        if (D("Admins/User")->deleteUser($id)) {
            $this->success("删除用户成功！");
        } else {
            $error = D('Admins/User')->getError();
            $this->error($error ? $error : '删除用户失败！');
        }
    }

    //批量处理信息(审核,取消审核,删除)
    public function batch() {
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            $doAct=I('get.do');
            switch($doAct){
                case 'checkpass':
                    $data=array('status'=>true);
                    $msg='审核';
                    break;
                case 'cancelpass':
                    $data=array('status'=>false);
                    $msg='取消审核';
                    break;
            }
            foreach ($ids as $id) {
                M('user')->where(array('userid'=>$id))->save($data);
            }
            $this->success($msg.'成功！');
        }
    }


    //批量删除用户
    public function deleteAll(){
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            foreach ($ids as $id) {
                if(D('Admins/User')->deleteUser($id)){
                    continue;
                }else{
                    $error = D('Admins/User')->getError();
                    $this->error($error ? $error : '删除用户失败！');
                }
            }
            $this->success('用户信息删除成功！');
        }
    }
    //获取市区
    public function getCity(){
        $province_id=I('id',0,'intval');
        if(empty($province_id)){
            exit(json_encode($this->error('错误省份ID')));
        }
        $map['province_id']=$province_id;
        $map['state']=true;
        $data=M('city')->field('city_id as id,city_name as name')->where($map)->select();
        echo json_encode($data);
    }

   //获取地区/县
    public function getArea(){
        $city_id=I('id',0,'intval');
        if(empty($city_id)){
            exit(json_encode($this->error('错误省市ID')));
        }
        $map['city_id']=$city_id;
        $data=M('area')->field('area_id as id,area_name as name')->where($map)->select();
        echo json_encode($data);
    }


    //获取用户订单
    public function myorder(){
        $userid=I('userid',0,'intval');
        if(empty($userid)){
            $this->error('用户ID错误!');
        }
        $data=M('user_orderlist')->field('daid,order_status,pay_time,finish_time,confirm_time',true)->select();
        foreach ($data as $key=>$value) {
            $pdata[$key]=M('items')->field(array('itemname','itemprice'))->where(array('itemid'=>$value['itemid']))->find();
            $datas[$key]=array_merge($data[$key],$pdata[$key]);
        }
        $this->assign('orderlist',$datas)->display();
    }


    //获取订单详情
    public function orderDetail(){
        $orderid=I('orderid',0,'intval');
        if(empty($orderid)){
            $this->error('订单不存在');
        }
        $this->display();
    }


    /**
     * 留言管理
     */
    public function message(){

        if (IS_POST) {
            $this->redirect('message', $_POST);
        }
        //搜索
        $search = I('get.search');
        if (!empty($search)) {
            $this->assign("search", $search);
            //添加开始时间
            $start_time = I('get.start_time');
            if (!empty($start_time)) {
                $start_time = strtotime($start_time);
                $where['create_time'] = array("EGT", $start_time);
                $this->assign('start_time', $start_time);
            }
            //添加结束时间
            $end_time = I('get.end_time');
            if (!empty($end_time)) {
                $end_time = strtotime($end_time);
                $where['create_time'] = array("ELT", $end_time);
                $this->assign('end_time', $end_time);
            }
            //时间搜索条件
            if ($end_time > 0 && $start_time > 0) {
                $where['create_time'] = array(array('EGT', $start_time), array('ELT', $end_time));
            }
            //是否审核
            $status = I('get.status', 2, 'intval');
            if ($status!=2) {
                $where["status"] = array("EQ", $status);
            }
            $this->assign("status", $status);

            //类别
            $types = I('get.types', null, 'intval');
            if(!empty($types)){
                $this->assign("types", $types);
                $where['type'] = array("EQ", $types);

            }

            //搜索字段
            $searchtype = I('get.searchtype', null, 'intval');
            //搜索关键字
            $keyword = \Input::getVar(I('get.keyword'));
            if (!empty($keyword)) {
                $this->assign("searchtype", $searchtype);
                $this->assign("keyword", $keyword);
                if ($searchtype ==2) {
                    $where['content'] = array("LIKE", "%{$keyword}%");
                }elseif ($searchtype==1) {
                    $userid=M('User')->where(array('nickname'=>$keyword))->getField('userid');
                    $where['userid']=array('EQ',(int) $userid);
                }
            }

        }else{
            $this->assign('status',2);
        }

        $model=M('UserMessage');
        $count = $model->where($where)->count();
        $page = $this->page($count, 20);
        $data = $model->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("id" => "DESC"))->select();
		
        $this->assign('Page', $page->show());
        $this->assign('count', $count);
        $this->assign('data', $data);
        $this->display();

    }
    
    /*
     * 评论详情
     * yf 0916
     */
    public function views()
    {
    	$id = I('get.id');
    	$model = M('UserMessage');
    	$parent_id = $model->where(array('id' => $id))->getField('parent_id');
    	$mid = $parent_id != 0 ? $parent_id : $id;
    	$info = $model->where(array('id' => $mid))->find();
    	$info['childlist'] = $model->where(array('parent_id' => $mid))->order("create_time asc")->select();
    	$this->assign("list", $info);
    	$this->assign("id", $id);
    	$this->assign("type", $info['type']);
    	$this->assign("mid", $mid);
    	$this->display();
    }
    
    /*
     * 评论处理函数
     * yf 0916
     */
    public function yf_replymsg()
    {
    	$post=I('post.');
    	if(empty($post)){
            $this->error('回复出错,请稍候再试!');
        }
        $post['create_time']=time();
        $post['userid'] = 0;
        $post['parent_id'] = empty($post['parent_id']) ? 0 : intval($post['parent_id']);
        if($post['touserid'] == 0)
        {
        	$this->error("自己不能回复自己的留言");
        }
        $type=$post['type'];
        if($type==1){
        	$table='Works';
        	$map['workid']=$post['infoid'];
        }elseif($type==2){
        	$table='User';
        	$map['userid']=$post['infoid'];
        }elseif($type==3){
        	$table='TryReport';
        	$map['id']=$post['infoid'];
        }elseif($type==4){
        	$table='Suipai';
        	$map['id']=$post['infoid'];
        }elseif($type==5){
        	$table='News';
        	$map['id']=$post['infoid'];
        }elseif($type==6){
        	$table='Activity';
        	$map['id']=$post['infoid'];
        }elseif($type==7)
        {
            $table="Teachlist";
            $map['teachid'] = $post['infoid'];
        }
        
        if(D('Admins/User')->sendMessage($post,$post['type'])){
        	optMsgnum($table,$map,'add');
        	$this->success('回复成功');
        }else{
        	$error = D('Admins/User')->getError();
        	$this->error($error ? $error : '回复失败,请稍候再试！');
        }
    }

    //批量处理信息(审核,取消审核,删除)
    public function message_batch() {
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            $doAct=I('get.do');
            switch($doAct){
                case 'checkpass':
                    $data=array('status'=>true);
                    $msg='审核';
                    break;
                case 'cancelpass':
                    $data=array('status'=>false);
                    $msg='取消审核';
                    break;
            }
            foreach ($ids as $id) {
                $item=M('UserMessage')->field('userid,status,type')->where(array('id'=>$id))->find();

                M('UserMessage')->where(array('id'=>$id))->save($data);

                if($doAct=='checkpass' && $item['status']==false){
                    $savearr['msgnum'] = array('exp','msgnum+1');
                }elseif($doAct=='cancelpass' && $item['status']==true){
                    $savearr['msgnum'] = array('exp','msgnum-1');
                }

                $table=getMsgTable($item['type']);
                if($table=='Works'){
                    $keyid='workid';
                }elseif($table=='User'){
                    $keyid='userid';
                }else{
                    $keyid='id';
                }
                M(getMsgTable($item['type']))->where(array($keyid=>$id))->save($savearr);

            }
            $this->success($msg.'成功！');
        }
    }

    //批量删除用户
    public function message_deleteAll(){
        if (IS_POST) {
            $idss = $_POST['ids'];
            if (!$idss) {
                $this->error('没有信息被选中!');
            }
            $ids = array();
            $type = false;
            if(!is_array($idss))
            {
            	$ids[] = $idss;
            	$type = true;
            }
            else 
            {
            	$ids = $idss;
            }

            foreach ($ids as $id) {
            	$parent_id = M('UserMessage')->where(array('id' => $id))->getField('parent_id');
            	$msginfo=M('UserMessage')->field('userid,type,infoid')->where(array('id'=>$id))->find();

	            if($msginfo['type']==1){
		            $table='Works';
		            $map['workid']=$msginfo['infoid'];
		        }elseif($msginfo['type']==2){
		            $table='User';
		            $map['userid']=$msginfo['infoid'];
		        }elseif($msginfo['type']==3){
		            $table='TryReport';
		            $map['id']=$msginfo['infoid'];
		        }elseif($msginfo['type']==4){
		            $table='Suipai';
		            $map['id']=$msginfo['infoid'];
		        }elseif($msginfo['type']==5){
		            $table='News';
		            $map['id']=$msginfo['infoid'];
		        }elseif($msginfo['type']==6){
		            $table='Activity';
		            $map['id']=$msginfo['infoid'];
		        }elseif($msginfo['type'] == 7)
		        {
		            $table="Teachlist";
		            $map['teachid']=$msginfo['infoid'];
		        }
            	
            	if($parent_id == 0)
            	{
            		$yf_id = M('UserMessage')->where(array('parent_id' => $id))->field('id')->select();
            		if($yf_id)
            		{
            			foreach($yf_id as $yk => $yv)
            			{
            				if(M('UserMessage')->delete($yv['id']))
            				{
                                service('Passport')->userDynamic($yv['userid'],4,'留言违规扣除4个积分',0,'message');
            					optMsgnum($table,$map,'del');
            				}
            			}
            		}
	            		
	            }
	            
	            if(M('UserMessage')->delete($id))
	            {
                    service('Passport')->userDynamic($msginfo['userid'],4,'留言违规扣除4个积分',0,'message');
	            	optMsgnum($table,$map,'del');
	            }
            
            }
            
        
        $this->success('留言信息删除成功！', '/Admins/User/message');
            
        }
    }


    /**
     * 站内信
     */
    public function sysmsg(){
        if (IS_POST) {
            $this->redirect('sysmsg', $_POST);
        }
        //搜索
        $search = I('get.search');
        if (!empty($search)) {
            $this->assign("search", $search);
            //添加开始时间
            $start_time = I('get.start_time');
            if (!empty($start_time)) {
                $start_time = strtotime($start_time);
                $where['create_time'] = array("EGT", $start_time);
                $this->assign('start_time', $start_time);
            }
            //添加结束时间
            $end_time = I('get.end_time');
            if (!empty($end_time)) {
                $end_time = strtotime($end_time);
                $where['create_time'] = array("ELT", $end_time);
                $this->assign('end_time', $end_time);
            }
            //时间搜索条件
            if ($end_time > 0 && $start_time > 0) {
                $where['create_time'] = array(array('EGT', $start_time), array('ELT', $end_time));
            }

            //类别
            $types = I('get.types', null, 'intval');
            if(!empty($types)){
                $this->assign("types", $types);
                $where['type'] = array("EQ", $types);
            }

            //搜索字段
            $searchtype = I('get.searchtype', null, 'intval');
            //搜索关键字
            $keyword = \Input::getVar(I('get.keyword'));
            if (!empty($keyword)) {
                $this->assign("searchtype", $searchtype);
                $this->assign("keyword", $keyword);
                if ($searchtype ==2) {
                    $where['title'] = array("LIKE", "%{$keyword}%");
                }elseif ($searchtype==1) {
                    $userid=M('User')->where(array('nickname'=>$keyword))->getField('userid');
                    $where['userid']=array('EQ',(int) $userid);
                }
            }
        }

        $where['sendtype']=array('EQ',I('get.sendtype'));
        $this->assign('sendtype',I('get.sendtype'));
        $model=M('Sysmsg');
        $count = $model->where($where)->count();
        $page = $this->page($count, 20);
        $data = $model->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("id" => "DESC"))->select();


        $this->assign('Page', $page->show());
        $this->assign('count', $count);
        $this->assign('data', $data);
        $this->display();
    }


    /**
     * 站内信添加
     */
    public function sysmsgadd(){
        if(IS_POST){
            $post=$_POST;
            if(!empty($post['uname'])){
                $post['userid']=M('User')->where(array('uname'=>$post['uname']))->getField('userid');
                if(!$post['userid']){
                    $this->error('找不到该会员信息');
                }else{
                    unset($post['uname']);
                    $post['type']=2;
                }
            }else{
                unset($post['uname']);
                $post['type']=1;//1.系统消息
            }
            $post['create_time']=time();
            $post['ifread']=false;
            $post['sendtype']=1;
            $id = M('Sysmsg')->add($post);
            if($id){
            	$info['sysid'] = $id;
            	$info['userid'] = $post['userid']; 
            	$info['ifread'] = 0;
            	M('SysmsgLog')->data($info)->add();
                $this->success('信息添加成功',U('sysmsg'));
            }else{
                $this->error('信息添加失败');
            }

        }else{
            $this->display();
        }
    }


    public function sysmsgedit(){
        if(IS_POST){
            $post=$_POST;
            $id=$post['id'];
            if(!empty($post['uname'])){
                $post['userid']=M('User')->where(array('uname'=>$post['uname']))->getField('userid');
            }else{
                unset($post['uname']);
            }
            unset($post['id']);
            if(M('Sysmsg')->where(array('id'=>$id))->save($post)){
                $this->success('信息修改成功',U('sysmsg'));
            }else{
                $this->error('信息修改失败');
            }
        }else{
            $id=I('get.id');
            $data=M('Sysmsg')->where(array('id'=>$id))->find();
            if(!empty($data['userid'])){
                $this->uname=M('User')->where(array('userid'=>$data['userid']))->getField('uname');
            }
            $this->assign('data',$data);
            $this->display();
        }
    }

    /*
     * 站内信息删除
     */
    public function sysmsg_deleteAll(){
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            foreach ($ids as $id) {
                if(M('Sysmsg')->delete($id)){
                    $this->success('信息删除成功！');
                }else{
                    $this->error('信息删除失败');
                }
            }
        }else{
            $this->error('操作出现错误！');
        }
    }
    
    public function teachlist()
    {
        if (IS_POST) {
            $this->redirect('teachlist', $_POST);
        }
        $get = I('get.');
        //搜索
        $search = I('get.search');
        if (!empty($search)) {
            $this->assign("search", $search);

            $searchtype = I('get.searchtype', null, 'intval');
            //搜索关键字
            $keyword = \Input::getVar(I('get.keyword'));
            if (!empty($keyword)) {
                $this->assign("searchtype", $searchtype);
                $this->assign("keyword", $keyword);
                $type_array = array('nickname', 'umobile', 'uemail');
                if ($searchtype < 3) {
                    $searchtype = $type_array[$searchtype];
                    $where[$searchtype] = array("LIKE", "%{$keyword}%");
                }
            }
        }
        if(empty($get['status']))
        {
            $where['ifds'] = 1;
        }
        else 
        {
            $where['ifds'] = $get['status'];
        }
        $model=M('user');
        $count = $model->where($where)->count();
        $page = $this->page($count, 20);
        $data = $model->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("userid" => "DESC"))->select();
        
        
        $this->assign('Page', $page->show());
        $this->assign('count', $count);
        $this->assign('data', $data);
        
        $this->display();
    }
    
    public function teachbatch() {
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            $doAct=I('get.do');
            switch($doAct){
                case 'checkpass':
                    $data=array('ifds'=>true);
                    $msg='审核';
                    break;
                case 'cancelpass':
                    $data=array('ifds'=> '-1');
                    $msg='取消审核';
                    break;
            }
            foreach ($ids as $id) {
                M('User')->where(array('userid'=>$id))->save($data);
                if($doAct == 'checkpass')
                {
                    $oldrz = M('User')->where(array('userid' => $id))->getField('ifrz');
                    if(!$oldrz)
                    {
                        M('User')->where(array('userid'=>$id))->save(array('ifrz' => 1));
                    }
                }
            }
            $this->success($msg.'成功！');
        }
    }

    /*
     *会员数据导出数据
     */
    public function userexcel(){
        $model=M('user');
        $where['uemail'] = array("NOTLIKE", "hb%@163.com");
        $dataes = $model->field('nickname,uemail,umobile,create_time')->where($where)->select();
        $data = array();
        foreach ($dataes as $k => $v) {
            $data[$k]['nickname'] = $v['nickname'];
            $data[$k]['n'] ='';
            $data[$k]['uemail'] = $v['uemail'];
            $data[$k]['m'] = '';
            $data[$k]['umobile'] = $v['umobile'];
            $data[$k]['ms'] = '';
            $data[$k]['create_time'] = date('Y-m-d H:i',$v['create_time']);
        }

        $title = array('昵称','','邮箱','','手机','','注册时间');
        $this->exportexcel($data,$title,iconv('UTF-8', 'gb2312', '会员信息资料'.date('Y-m-d H:i:s',time())));
    }

    /**
     * 导出数据为excel表格
     *@param $data    一个二维数组,结构如同从数据库查出来的数组
     *@param $title   excel的第一行标题,一个数组,如果为空则没有标题
     *@param $filename 下载的文件名
     *@examlpe
     $stu = M ('User');
     $arr = $stu -> select();
     exportexcel($arr,array('id','账户','密码','昵称'),'文件名!');
     */
    private function exportexcel($data = array(), $title = array(), $filename = 'report') {
        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:attachment;filename=".$filename.".xls");
        header("Pragma: no-cache");
        header("Expires: 0");
        
           if (!empty($title)){
                foreach ($title as $k => $v) {
                    $title[$k]=iconv("UTF-8", "GB2312",$v);
                }
                $title= implode("\t", $title);
                echo "$title\n";
            }
            if (!empty($data)){
                foreach($data as $key=>$val){
                    foreach ($val as $ck => $cv) {
                        $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
                    }
                    $data[$key]=implode("\t", $data[$key]);
                    
                }
                echo implode("\n",$data);
            }

    }

     //上传excel 表格
    public function excelUploads()
    {
        $user = M('User')->field('openuid')->order('userid DESC')->find();
        $openuid = $user['openuid'];
        $upfile = $_FILES['import'];
       //上传文件类型列表  
        $typelist = array('application/vnd.ms-excel');  
        $path = "./f/upload/15/"; //上传文件路径

        if($upfile['error'] > 0){
            $myfile = fopen("error.txt", "w");
            
            fwrite($myfile,date('y-m-d h:i:s',time()).' 错误代码:'.$upfile['error']);
            //die("上传错误");
            return 0;
        }
       
        if(!in_array($upfile["type"],$typelist)){
            //die("请上传excel表格");
            return 0;
        }
        
        if( $upfile['size'] > 1048500){
             //限制上传1M以下的图片
            return ; 
        }

        $fileinfo = pathinfo($upfile["name"]);
        $newfile = date("YmdHis").rand(100,999).".".$fileinfo["extension"]; //新名称
         
        if(is_uploaded_file($upfile["tmp_name"])){
            if(move_uploaded_file($upfile["tmp_name"],$path.$newfile)){
                
                 $this->goExcel($path.$newfile,'xls',$openuid);
                
            }
        }
       
      
      
       $url = U('/Admins/User/index/menuid/2');
        Header("Location:{$url}"); 
       
       
    }



    /*
     *读取excel表格数据的类
     *@param $filename 上传excel的路径
     *@param $exts 格式
     */
    private function goExcel($filename, $exts='xls',$openuid=0){
        //导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
        import("Org.Util.PHPExcel");
        //创建PHPExcel对象，注意，不能少了\
        $PHPExcel=new \PHPExcel();
        //如果excel文件后缀名为.xls，导入这个类
        if($exts == 'xls'){
            import("Org.Util.PHPExcel.Reader.Excel5");
            $PHPReader=new \PHPExcel_Reader_Excel5();
        }else if($exts == 'xlsx'){
            import("Org.Util.PHPExcel.Reader.Excel2007");
            $PHPReader=new \PHPExcel_Reader_Excel2007();
        }
         $PHPExcel=$PHPReader->load($filename);
         //载入文件
        $PHPExcel=$PHPReader->load($filename);
        //获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
        $currentSheet=$PHPExcel->getSheet(0);
        //获取总列数
        $allColumn=$currentSheet->getHighestColumn();
        //获取总行数
        $allRow=$currentSheet->getHighestRow();
        //循环获取表中的数据，$currentRow表示当前行，从哪行开始读取数据，索引值从0开始
        for($currentRow=2;$currentRow<=$allRow;$currentRow++){
            $data['type'] = 'type';
            $data['openuid'] = $openuid+$currentRow;
            $data['uname'] = $currentSheet->getCell('A'.$currentRow)->getValue();
            $data['nickname'] = $currentSheet->getCell('C'.$currentRow)->getValue();
            $data['uemail'] = $currentSheet->getCell('E'.$currentRow)->getValue();

            $Member = D("User/User");
            $pswd = $currentSheet->getCell('G'.$currentRow)->getValue();
            $password = $Member->encryption(0, $pswd, $encrypt);
            $data['upassword'] = $password;
            $data['logtimes'] = 1;
            $data['create_time'] = time();
            $data['login_time'] = time();
            $data['lastip'] = get_client_ip();
            $data['islock'] = 0;
            $data['upoint']= 0 ;
            $data['status'] = 1;
            $num = mt_rand(100,300);
            $data['uavatar'] = "/f/user/15/09/10/hbq_ln".$num.".jpg";
            $userId = M('User')->add($data);
            service('Passport')->userDynamic($userId,20,'注册获取20个积分',1,'register');

        }
        
    }
    
}
